1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import { auth, fd, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, params }) {
if (params.payreq.startsWith("lno")) return params;
const data = await post("/parse", params, auth(cookies));
data.payreq = params.payreq;
return data;
}
export const actions = {
setAmount: async ({ cookies, params, request }) => {
let data = await fd(request);
const { payreq } = params;
const { amount } = data;
if (payreq.startsWith("lno")) {
const { invoice } = await post("/fetchinvoice", {
amount,
offer: payreq,
});
data = await post("/parse", { payreq: invoice }, auth(cookies));
data.payreq = invoice;
}
return data;
},
send: async ({ cookies, request }) => {
let p;
try {
const body = await fd(request);
p = await post("/payments", body, auth(cookies));
} catch (e: any) {
if (
e.message.includes("unusable") ||
e.message.includes("routes") ||
e.message.includes("minflow")
)
e.message = "payments.failedToRoute";
return fail(400, { message: e.message });
}
redirect(307, `/sent/${p.id}`);
},
};
|